<template>
  <div class="dashboard-editor-container">
    <el-row :gutter="24">
      <el-col :sm="24" :lg="12">
        <div class="chart-wrapper">
          <h5>综合统计</h5>
          <el-row :gutter="40" class="panel-group">
            <el-col :xs="12" :sm="12" :lg="12" class="card-panel-col">
              <div class="card-panel">
                <div class="card-panel-icon-wrapper icon-people">
                  <svg-icon icon-class="example" class-name="card-panel-icon" />
                </div>
                <div class="card-panel-description">
                  <div class="card-panel-text">
                    规则数/大类
                  </div>
                  {{ reportDetail.compTotal.confParent }}
                </div>
              </div>
            </el-col>
            <el-col :xs="12" :sm="12" :lg="12" class="card-panel-col">
              <div class="card-panel">
                <div class="card-panel-icon-wrapper icon-people">
                  <svg-icon icon-class="example" class-name="card-panel-icon" />
                </div>
                <div class="card-panel-description">
                  <div class="card-panel-text">
                    规则数/小类
                  </div>
                  {{ reportDetail.compTotal.confChildren }}
                </div>
              </div>
            </el-col>
            <el-col :xs="12" :sm="12" :lg="12" class="card-panel-col">
              <div class="card-panel">
                <div class="card-panel-icon-wrapper icon-people">
                  <svg-icon icon-class="example" class-name="card-panel-icon" />
                </div>
                <div class="card-panel-description">
                  <div class="card-panel-text">
                    测试字段数
                  </div>
                  {{ reportDetail.compTotal.planDetail }}
                </div>
              </div>
            </el-col>
            <el-col :xs="12" :sm="12" :lg="12" class="card-panel-col">
              <div class="card-panel">
                <div class="card-panel-icon-wrapper icon-people">
                  <svg-icon icon-class="example" class-name="card-panel-icon" />
                </div>
                <div class="card-panel-description">
                  <div class="card-panel-text">
                    测试方案数
                  </div>
                  {{ reportDetail.compTotal.plan }}
                </div>
              </div>
            </el-col>
          </el-row>
        </div>
      </el-col>
      <el-col :sm="24" :lg="12">
        <div class="chart-wrapper">
          <h5>规则调用统计</h5>
          <pie-chart v-if="refresh" :data="pieData" />
        </div>
      </el-col>

      <el-col :sm="24" :lg="24">
        <div class="chart-wrapper">
          <h5>测试结果统计</h5>
          <el-table
            ref="multipleTable"
            :data="reportDetail.testTesult"
            stripe
            border
            tooltip-effect="light"
            style="width: 100%"
          >
            <el-table-column
              label="序号"
              type="index"
              width="55"
              align="center"
            />
            <el-table-column
              align="center"
              prop="name"
              label="设备代码"
            />
            <el-table-column
              align="center"
              prop="testCount"
              label="测试量"
            />
            <el-table-column
              align="center"
              prop="errorCount"
              label="报错数"
              width="100"
            />
            <el-table-column
              align="center"
              prop="rate"
              label="报错率"
              width="100"
            />
          </el-table>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { reportDetail } from '@/api/plan'
import PieChart from './components/PieChart'

export default {
  name: 'QualityReport',
  components: { PieChart },
  data() {
    return {
      id: 1,
      reportDetail: {},
      refresh: false,
      pieData: {
        legend: {
          left: 'center',
          bottom: '10',
          data: []
        },
        series: [
          {
            name: 'WEEKLY WRITE ARTICLES',
            type: 'pie',
            roseType: 'radius',
            radius: [15, 95],
            center: ['50%', '38%'],
            data: [],
            animationEasing: 'cubicInOut',
            animationDuration: 2600
          }
        ]
      }
    }
  },

  created() {
    this.id = this.$route.params && this.$route.params.id
    this.getDetail()
  },

  methods: {
    getDetail() {
      reportDetail(this.id).then(res => {
        this.reportDetail = res.data

        this.reportDetail.planTotal.map(item => {
          this.pieData.series[0].data.push({ value: item.num, name: item.name })
          this.pieData.legend.data.push(item.name)

          this.$nextTick(() => {
            this.refresh = true
          })
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .panel-group {
    margin-top: 18px;

    .card-panel-col {
      margin-bottom: 42px;
    }

    .card-panel {
      height: 108px;
      cursor: pointer;
      font-size: 12px;
      position: relative;
      overflow: hidden;
      color: #666;
      background: #fff;
      box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
      border-color: rgba(0, 0, 0, .05);

      &:hover {
        .card-panel-icon-wrapper {
          color: #fff;
        }

        .icon-people {
          background: #40c9c6;
        }

        .icon-message {
          background: #36a3f7;
        }

        .icon-money {
          background: #f4516c;
        }

        .icon-shopping {
          background: #34bfa3
        }
      }

      .icon-people {
        color: #40c9c6;
      }

      .icon-message {
        color: #36a3f7;
      }

      .icon-money {
        color: #f4516c;
      }

      .icon-shopping {
        color: #34bfa3
      }

      .card-panel-icon-wrapper {
        float: left;
        margin: 14px 0 0 14px;
        padding: 16px;
        transition: all 0.38s ease-out;
        border-radius: 6px;
      }

      .card-panel-icon {
        float: left;
        font-size: 48px;
      }

      .card-panel-description {
        float: right;
        font-weight: bold;
        margin: 26px;
        margin-left: 0px;

        .card-panel-text {
          line-height: 18px;
          color: rgba(0, 0, 0, 0.45);
          font-size: 16px;
          margin-bottom: 12px;
        }

        .card-panel-num {
          font-size: 20px;
        }
      }
    }
  }
  .dashboard-editor-container {
    padding: 32px;
    background-color: rgb(240, 242, 245);
    position: relative;
  }

  .chart-wrapper {
    background: #fff;
    padding: 6px 16px 0;
    margin-bottom: 32px;
  }

  @media (max-width:1024px) {
    .chart-wrapper {
      padding: 8px;
    }
  }
</style>
